<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models\TestApi;

use Carbon\Carbon;
use App\Models\Eloquent;

/**
 * Class QtpTestModule
 *
 * @property int $id
 * @property string $test_report_uid
 * @property string $cate_name
 * @property string $project_name
 * @property string $product_name
 * @property string $f_module_name
 * @property string $s_module_name
 * @property int $test_api_sun
 * @property int $test_param_sun
 * @property int $s_module_id
 * @property int $success_param_sun
 * @property int $status
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 *
 * @package App\Models
 */
class TestModule extends Eloquent
{
	protected $table = 'test_modules';

	protected $casts = [
		'test_api_sun' => 'int',
		'test_param_sun' => 'int',
		'success_param_sun' => 'int',
        'status' => 'int',
        's_module_id' => 'int'
	];

	protected $fillable = [
		'test_report_uid',
		'cate_name',
		'project_name',
		'product_name',
		'f_module_name',
		's_module_name',
        's_module_id',
		'test_api_sun',
		'test_param_sun',
		'success_param_sun',
        'status'
	];

    const STATUS_INIT = 0;
    const STATUS_DONE = 1;
    public static $status_maps = [
        self::STATUS_INIT => '待测试',
        self::STATUS_DONE => '已测试',
    ];

    public function label()
    {
        $testReport = TestReport::getByUid($this->test_report_uid);
        $this->test_adminer = $testReport->test_adminer ?? '';
        $this->created_adminer = $testReport->created_adminer ?? '';
        $this->tested_at = $testReport->tested_at ?? '';
        $this->status_label = self::$status_maps[$this->status] ?? '';
        $this->test_validator_sum = TestValidatorRes::where('test_module_id', $this->id)->count();
        $this->success_validator_sum = TestValidatorRes::where('status', TestValidatorRes::STATUS_SUCCESS)->where('test_module_id', $this->id)->count();

        return $this;
    }


    public static $fillables = [
        'test_report_uid' => '测试报告唯一UUID',
        'cate_name' => '开发组名称',
        'project_name' => '项目名称',
        'product_name' => '产品名称',
        'f_module_name' => '主模块',
        's_module_name' => '子模块',
        's_module_id' => '原始子模块ID',
        'test_api_sun' => '测试接口总数',
        'test_param_sun' => '测试用例总数',
        'success_param_sun' => '测试成功用例总数',
        'status' => '测试单运行状态 0待跑 1已跑'
    ];
}
